import pygal
from die import Die


# 创建一个6面的骰子
d_6 = Die()


# 投掷若干次骰子，并将结果（点数）存储在一个列表中
results = []

for i in range(1000):
    LV_result = d_6.roll()
    results.append(LV_result)

# print(results)


# 统计结果
frequencies = []

for value in range(1, d_6.num_sides + 1):
    frequency = results.count(value)
    frequencies.append(frequency)

print(frequencies)


# 对结果进行可视化（直方图）
INS_hist = pygal.Bar()

INS_hist.title = "Results of rolling one D6 die 1000 times"     # 图标标题
INS_hist.x_labels = ["1", "2", "3", "4", "5", "6"]           # x 轴标签
INS_hist.x_title = "Result"  # x轴标题
INS_hist.y_title = "Frequency"  # y轴标题

INS_hist.add("D6", frequencies)  # 要绘制的数据
INS_hist.render_to_file("die_visual.svg")   # 保存为矢量图
